package com.wwwc.index.web.servlet;

import java.io.*;
import java.awt.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletRequestWrapper;
import java.net.*;
import java.security.Security;
import java.security.Provider;
import javax.net.ssl.*;

import com.wwwc.util.web.*;
import com.wwwc.index.web.ejb.database.*;
import com.wwwc.index.web.ejb.*;

public class Membership {
    private EJBDatabaseQuery ejbdb;

    public StringBuffer listStoragePrice (String call_path, String mid, String payment_call_back, String error) {
	StringBuffer sbf = new StringBuffer ();	
	try {
	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }
	    if(error != null) {
		sbf.append("<img src=/images/star.gif><I>"+error+"</I>");
	    }

	    sbf.append("<FORM method=post action="+call_path+">");
	    sbf.append("<TABLE cellSpacing='0' cellPadding='0' border='1' width='80%'>");
	    ArrayList aa = ejbdb.select("SELECT * FROM USER_STORAGE_PRICE WHERE MID="+mid+";"); 
	    Iterator it = aa.iterator();
	    ArrayList a = null;
	    int id = 0;
	    double price = 0.0;
	    int duration = 0;
	    int storage  = 0;
	    Hashtable duhs = new Hashtable();
	    duhs.put("30", "Month");
	    duhs.put("365", "Year");
	  
	    sbf.append("<TR><TD align=center><B>Price</B></TD><TD align=center><B>Storage Size</B></TD>");
	    sbf.append("<TD align=center><B>Select</B></TD><TD align=center><B>Refund Policy</B></TD></TR>");
	    while (it.hasNext()) {
		a = (ArrayList)it.next();
		id = Integer.parseInt((String)a.get(0));
		price = Double.parseDouble((String)a.get(2));
		duration = Integer.parseInt((String)a.get(3));
		storage = Integer.parseInt((String)a.get(4));
		sbf.append("<TR><TD align=center>"+price+"/"+duhs.get(""+duration)+"</TD>");
		sbf.append("<TD align=center>"+storage/1000000+"Mb</TD>");
		sbf.append("<TD align=center><input type=radio name=storage_id value="+id+"></TD>");
		sbf.append("<TD align=center>"+a.get(5)+"</TD>");
		sbf.append("</TR>");
	    }
	    sbf.append("<TR><TD align=center colspan=4>");
	    sbf.append("<BR><input type=submit name=add_storage value=Add style='font-size:8pt'><BR><BR>");
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");
	    sbf.append("<input type=hidden name=mid value="+mid+">");
	    sbf.append("<input type=hidden name=aid value="+payment_call_back+">");
	    sbf.append("</FORM>");
	}
	catch(Exception e) {
	    System.out.println("Membership:userStoragePrice:Error:"+e);   
	}
	return sbf;
    }
}
